﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Microsoft.TownHall.ServiceClient
{
    [XmlRoot(ElementName = "Nuggets")]
    public class NuggetList : List<Nugget> { }
    public class Nugget
    {

        public Nugget()
        {
            NuggetOriginator = new Originator();
            Votes = new Votes();
            
        }
        public int NuggetID { get; set; }
        public string Subject { get; set; }
        public string SubjectSlug { get; set; }
        public string Category { get; set; }
        public string CategoryName { get; set; }
        public string Body { get; set; }
        public Originator NuggetOriginator { get; set; }

        public Votes Votes { get; set; }
        public long TopNuggetVoteCount { get; set; }
        public string NuggetFlags { get; set; }
        public DateTime DateCreated { get; set; }
        public DateTime DateModified { get; set; }
        [XmlArray("UserSpecificTags")]
        [XmlArrayItem("UserSpecificTagName", Type = typeof(string))]
        public List<string> UserSpecificTags { get; set; }
        public ResponseList Responses { get; set; }

    }
    public class Originator
    {
        public long UserID { get; set; }
        public string DisplayName { get; set; }
        public string DisplayNameSlug { get; set; }
        public string EmailHash { get; set; }
        public long UserReputationPoints { get; set; }
        public string UserReputationString { get; set; }

        private string _Avatar;

        public string Avatar 
        {
            get
            {
                if (!String.IsNullOrEmpty(_Avatar))
                {
                    if (_Avatar.Length > 20)
                    {
                        _Avatar = _Avatar.Replace(
                            "Content/Themes/CraterCity/Images/Avatars/", 
                            "s/img/avatars/avatar-");

                        _Avatar = _Avatar.Replace(
                            "-60px.png", 
                            "-pp-sm.png");

                        return _Avatar;
                    }
                    else
                    {
                        _Avatar = String.Format("{0}/s/img/avatars/avatar-{1}-pp-sm.png", THServiceClient.BASE_URL, _Avatar);
                        return _Avatar;
                    }
                }

                return _Avatar;
            }
            set
            {
                _Avatar = value;
            }
        }
    }

    [XmlRoot(ElementName = "Votes")]
    public class Votes
    {
        public Votes()
        { 
            CurrentUserVote = new CurrentUserVote(); 
        }
        [XmlElement(ElementName = "UpVotes", Type = typeof(long))]
        public long UpVotes { get; set; }
        [XmlElement(ElementName = "DownVotes", Type = typeof(long))]
        public long DownVotes { get; set; }
        [XmlElement(ElementName = "UpPercentage", Type = typeof(float))]
        public float UpPercentage { get; set; }
        [XmlElement(ElementName = "DownPercentage", Type = typeof(float))]
        public float DownPercentage { get; set; }
        [XmlElement(ElementName ="CurrentUserVote", Type = typeof(CurrentUserVote))]
        public CurrentUserVote CurrentUserVote { get; set; }
    }
    [XmlRoot(ElementName="CurrentUserVote")]
    public class CurrentUserVote
    {
        [XmlElement(ElementName = "HasVoted", Type = typeof(bool))]
        public bool HasVoted { get; set; }
        [XmlElement(ElementName = "NuggetID", Type = typeof(long))]
        public long NuggetID { get; set; }

    }

}
    